package com.zx._10_设计模式._0_综合案例.奖励的发放策略;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangxue
 */
public class StrategyContext {

    private static final Map<String, Strategy> registerMap = new HashMap<>();

    /**
     * 注册策略
     * @param rewardType
     * @param strategy
     */
    public static void registerStrategy(String rewardType, Strategy strategy) {
        System.out.println("registerStrategy rewardType=" + rewardType + ", strategy=" + strategy.getClass());
        registerMap.putIfAbsent(rewardType, strategy);
    }

    /**
     * 获取策略
      */
    public static Strategy getStrategy(String rewardType) {
        Strategy strategy = registerMap.get(rewardType);
        if(strategy == null){
            throw new RuntimeException("strategy not find:" + rewardType);
        }
        return strategy;
    }
}
